<template>
	<view class=" ">
		<view class="bg-white p-10">
			<view v-for="(item,index) in list" :key="index">
				<view class="banmi_sete_view">
					<view class="sete_name">{{item.name}}:</view>

					<template v-if="item.type=='input'">
						<view class="sete_text">{{find[item.fields]}}</view>
						<view class="">
							<button type="primary" size="mini" @click="on_set_key(item.name,item.fields)"
								class="banmi_but">
								设置
							</button>
						</view>
					</template>
					<template v-if="item.type=='select'">
						<view class="sete_text">
							<view @click="on_select(vo.type,item.fields)" v-for="(vo,index1) in item.list">
								<button style="flex-shrink:0; background: transparent;" class="banmi_flex a-c m-l-10">
									<view class="q-y  banmi_flex a-c j-c"
										:class="find[item.fields] == vo.type ? 'key_xz' : 'key_wxz'">
										<text v-if="find[item.fields]== vo.type " class="f-14">✓</text>
									</view>
									<text class="f-14 c_7" style="margin-left: 5px;"
										:class="find[item.fields]== vo.type ? 'key_color' : ''">{{vo.name}}</text>
								</button>
							</view>
						</view>
					</template>

					<template v-if="item.type=='switch'">
						<view class="sete_text">
							{{find[item.fields]==1? item.switch_find.on_name:item.switch_find.off_name }}
						</view>
						<view @click="on_switch(find[item.fields],item.fields)">
							<banmi-switch :is_state="Number(find[item.fields])"></banmi-switch>
						</view>
					</template>

				</view>
			</view>


		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-beizhu cancelText="取消" confirmText="确认" lei="0" :name="name" :key="key" @confirm="ajax_set">
			</uni-popup-beizhu>
		</uni-popup>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				list: [{
						name: '前台同一ip并且同一接口每分钟限制访问几次(次)',
						fields: 'app_c_interceptor',
						type: 'input'
					},
					{
						name: '前台同一ip并且同一接口超出后提示',
						fields: 'app_c_msg',
						type: 'input'
					},
					{
						name: '前台同一ip每分钟限制访问几次',
						fields: 'app_ip_interceptor',
						type: 'input'
					},
					{
						name: '前台同一ip超出后提示',
						fields: 'app_ip_msg',
						type: 'input'
					},
					{
						name: '后台同一ip并且同一接口每分钟限制访问几次',
						fields: 'admin_c_interceptor',
						type: 'input'
					},
					{
						name: '后台同一ip并且同一接口超出后提示',
						fields: 'admin_c_msg',
						type: 'input'
					},
					{
						name: '后台同一ip每分钟限制访问几次',
						fields: 'admin_ip_interceptor',
						type: 'input'
					},
					{
						name: '后台同一ip超出后提示',
						fields: 'admin_ip_msg',
						type: 'input'
					},
				],
				find: {},
				name: '',
				key: ''
			}
		},
		onLoad() {
			this.init();
		},
		methods: {
			async init() {
				const ret = await this.Banmikeji.saaslist_set_index({});
				this.find = ret.data.data;
			},
			on_set_key(name, key) {
				this.name = name;
				this.key = key;
				this.$refs.alertDialog.open()
			},
			async ajax_set(val) {
				var that = this;
				that.requestParams = {};
				that.requestParams[that.key] = val
				that.requestParams['key'] = that.key

				const ret = await this.Banmikeji.saaslist_set_key_limiting(that.requestParams);
				if (ret.data.status == 200) {
					this.find[that.key] = val;
					this.$refs.alertDialog.close()
				}

			},
		}
	}
</script>

<style>
	button {
		padding: 0;
	}
</style>